package model;

import static org.junit.Assert.*;

import java.util.GregorianCalendar;

import org.junit.Before;
import org.junit.Test;

public class SparePartTest {

	private SparePart sp;

	/**
	 * @author Osahon Idehen
	 */

	@Before
	public void setUp() throws Exception {
		sp = new SparePart(2203459, 331, 311, 321, "Sp", 3, 32, 7, "for GS20");

		new SparePartHistory(new GregorianCalendar(2008, GregorianCalendar.MAY,
				12), null, new SparePartUse(6, sp));
		new SparePartHistory(new GregorianCalendar(2008,
				GregorianCalendar.APRIL, 12), null, new SparePartUse(10, sp));

		new SparePartHistory(new GregorianCalendar(2008,
				GregorianCalendar.JANUARY, 12), null, new SparePartUse(16, sp));
		new SparePartHistory(new GregorianCalendar(2008,
				GregorianCalendar.JANUARY, 15), null, new SparePartUse(10, sp));

	}

	/**
	 * This method getmonthlyUseOfSparePart, get only the month and year
	 *  of spare part use.
	 */
	@Test
	public void testgetMonthlyUseOfSparePart1() {
		int result = sp.getMonthlyUseOfSparePart(new GregorianCalendar(2008,
				GregorianCalendar.JANUARY, 30));
		/**
		 * This compares the expected and actual objects. It is expected to
		 * be null and that implies that they are equal object. futomiss
		 */
		assertEquals(result, 26);
	}

	@Test
	public void testgetMonthlyUseOfSparePart2() {
		int result = sp.getMonthlyUseOfSparePart(new GregorianCalendar(2008,
				GregorianCalendar.APRIL, 12));
		assertEquals(result, 10);
	}

	@Test
	public void testgetMonthlyUseOfSparePart3() {
		int result = sp.getMonthlyUseOfSparePart(new GregorianCalendar(2008,
				GregorianCalendar.MAY, 12));
		assertEquals(result, 6);
	}

	@Test
	public void testgetMonthlyUseOfSparePart4() {
		int result = sp.getMonthlyUseOfSparePart(new GregorianCalendar(2008,
				GregorianCalendar.JULY, 12));
		assertEquals(result, 0);
	}

	@Test
	public void testgetMonthlyUseOfSparePart5() {
		/**
		 *  Error in this method, but we didn't get the time to fix it.
		 */ 
		int result = sp.getMonthlyUseOfSparePart(new GregorianCalendar(2008,
				GregorianCalendar.APRIL, 1), new GregorianCalendar(2008,
				GregorianCalendar.MAY, 30));
		assertEquals(result, 42);
	}
}